{% extends 'AdminBundle::layout.html.twig' %}

    {% block title %}登录{% endblock %}

    {% block css %}{% endblock %}


    {% block top %}{% endblock %}

    {% block body %}
    <div class="login-wrapper">
        <div class="auth-box">
            <div class="login-layout">
                <div class="o-login-logo">
                    <img src="{{ asset('assets/img/icon/o-login-logo.png') }}" width="210" height="45">
                </div>

                <div class="auth-mes">
                    <div class="auth-input">
                        <span class="user-icon"></span>
                        <input type="text" class="login-input" name="name" placeholder="用户名">
                    </div>

                    <div class="auth-input" style="margin-top: 36px;">
                        <span class="user-pass"></span>
                        <input type="password" class="login-input" name="password" placeholder="密码">
                    </div>
                </div>

                <a class="forget-text" href="{{ path('auth_forget_password') }}">忘记密码?</a>

                <div class="whether-pass">
                    {#<span class="w-icon y-icon"></span>#}
                    {#<span class="wh-text">记住用户名和密码</span>#}
                </div>

                <button class="auth-btn">登&nbsp;录</button>
            </div>
        </div>

        <div class="l-copyright">Copyright @ 2001-2017 All right Reserved</div>
    </div>
    {% endblock %}

{% block right_body %}
{% endblock %}


{% block javascript %}
<script type="text/javascript">
    $(function() {
        $('.w-icon').on('click', function() {
            $(this).toggleClass('y-icon');
        });

        $('.auth-btn').on('click', function() {
            var username = $.trim($('input[name="name"]').val());
            var password = $.trim($('input[name="password"]').val());

            if (username == '') {
                popStatus(2, '请输入用户名', 1,'', true);
                return;
            }

            if (password == '') {
                popStatus(2, '请输入密码', 1,'', true);
                return;
            }

            if(!(/^1[3|4|5|7|8]\d{9}$/.test(username))){
                popStatus(2, '手机号码格式错误', 1,'', true);
                return;
            }

            if (6 > password.length || password.length > 20) {
                popStatus(2, '密码长度要在6~20位之间', 1,'', true);
                return;
            }

            $.post("{{ path('api_admin_auth_login') }}",{"phone":username,"password":password},function(data){
                console.log(data);
                if(data.errorCode == 0){
                    popStatus(1, '登录成功', 1,'{{ path('admin_index') }}', true);
                } else {
                    popStatus(2, data.message, 1,'', true);
                }
            })

        })
    })
</script>
{% endblock %}

